package com.bff.gaia.streaming.api.xjoin.client.hbase.core.utils;

import com.bff.gaia.streaming.api.xjoin.core.utils.ByteUtils;
import org.apache.hadoop.hbase.util.Bytes;

public class HbaseUtils {
	public static Object convertByte(byte[] hbaseData, String type){
		if(type == null){
			return new String(hbaseData);
		}

		switch (type.toLowerCase()) {
			case "boolean":
				return Bytes.toBoolean(hbaseData);

			case "int":
				return Bytes.toInt(hbaseData);

			case "bigint":
				return Bytes.toLong(hbaseData);

			case "tinyint":
			case "byte":
				return ByteUtils.bytes2Byte(hbaseData);

			case "short":
			case "smallint":
				return Bytes.toShort(hbaseData);

			case "char":
			case "varchar":
			case "string":
				return Bytes.toString(hbaseData);

			case "float":
				return Bytes.toFloat(hbaseData);

			case "double":
				return Bytes.toDouble(hbaseData);

		}

		throw new RuntimeException("not support type of " + type);
	}
}